package com.alfred.springboot.handlerinterceptor.interceptor;

import cn.hutool.core.util.StrUtil;
import com.alfred.springboot.handlerinterceptor.util.HeaderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @author: alfred
 * @date: 2021/7/20
 * @description: 登录拦截器
 */
@Component
@Slf4j
public class LoginPermissionInterceptor implements HandlerInterceptor {

    /**
     * 跳过token检查的接口
     */
    private List<String> skipCheckToken = Arrays.asList(
    );

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 从 http 请求头中取出 token，判断是否过期，如果过期则返回 false，否则返回 true
        // 此处只判断 token 是否为空
//        String token = HeaderUtil.getToken(request);
//        if(StrUtil.isEmpty(token)){
//            return false;
//        }
        return true;
    }


    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           @Nullable ModelAndView modelAndView) throws Exception {
        // Do nothing
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
                                @Nullable Exception ex) throws Exception {
        // Do nothing
    }

}
